package cn.wolfcode.p2p.web.controller;

import cn.wolfcode.p2p.base.domain.UserInfo;
import cn.wolfcode.p2p.base.service.ISystemDictionaryItemService;
import cn.wolfcode.p2p.base.service.ISystemDictionaryService;
import cn.wolfcode.p2p.base.service.IUserInfoService;
import cn.wolfcode.p2p.base.util.JSONResult;
import cn.wolfcode.p2p.web.util.RequiredLogin;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

@Controller
@RequestMapping("/basicInfo")
public class UserInfoController {
    @Autowired
    private IUserInfoService userInfoService;
    @Autowired
    private ISystemDictionaryItemService systemDictionaryItemService;

    // 进入资本资料界面,需要登录
    @RequestMapping
    @RequiredLogin
    public String toBasicInfoPage(Model model) {
        model.addAttribute("userInfo", userInfoService.getCurrent());
        model.addAttribute("educationBackgrounds", systemDictionaryItemService.listItemBySn("educationBackgrounds"));
        model.addAttribute("incomeGrades", systemDictionaryItemService.listItemBySn("incomeGrades"));
        model.addAttribute("marriages", systemDictionaryItemService.listItemBySn("marriages"));
        model.addAttribute("kidCounts", systemDictionaryItemService.listItemBySn("kidCounts"));
        model.addAttribute("houseConditions", systemDictionaryItemService.listItemBySn("houseConditions"));
        return "userInfo";
    }

    // 保存/更新个人基本资料信息
    @PostMapping("/save")
    @RequiredLogin
    @ResponseBody
    public JSONResult saveBasicInfo(UserInfo vo) {
        userInfoService.saveBasicInfo(vo);
        return new JSONResult();
    }
}
